let webpack = require('webpack');
let path = require('path');
let ExtractTextPlugin = require("extract-text-webpack-plugin");
let ResPlugin=require('xtouch-res-webpack-plugin');
let res =require('./res.config/res.config');
module.exports = {
    entry: res.entry,
    output: {
        path: path.join(__dirname, res.publicPath),
        // filename: '[chunkhash:8].[name].js',
        filename: './js/[chunkhash:8].js',
        chunkFilename: "./js/[chunkhash:8].js",
        publicPath: res.cdn+res.version+'/',
	    // library: "",
	    libraryTarget: "umd"
    },
    module: {
        rules: [
           {
                test: /\.css$/,
                use: ['style-loader',{
                        loader: 'css-loader',
                        options: {
                            minimize: true
                        }
                    }
                ]
            },
            {
                test: /\.js$/,
                //exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015-loose'], // 更贴近ES5，可兼容更多浏览器，比如说IE9
                    'plugins': [
                        'transform-remove-strict-mode',
                        'transform-es3-property-literals',
                        'transform-es3-member-expression-literals'
                    ]
                } 
            },

            {
                test: /\.(scss)$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: [{
                        loader: 'css-loader',
                        options: {
                            minimize: true
                        }
                    },"sass-loader"]
                })
            },

            {
                test: /\.(gif|jpg|png|svg)\??.*$/,
                loader: 'url-loader?limit=8192&name=images/[hash:8].[ext]'
            } ,
            {
                test: /\.(woff|eot|ttf)\??.*$/,
                loader: 'url-loader?limit=8192&name=font/[hash:8].[ext]'
            },
            { //解析 .ejs
                test: /\.ejs/,
                loader: 'ejs-loader'
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin('css/[contenthash:8].css'),
        new ResPlugin(res),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                properties: false,
                warnings: false
            },
            output: {
                beautify: true,
                quote_keys: true
            },
            mangle: {
                screw_ie8: false
            },
            sourceMap: false
        }),

    ]
}
